<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@include file="/common.jsp"%>
<!DOCTYPE html>
<html lang="zh">
<meta charset="utf-8">
<head></head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-ledger-add" enctype="multipart/form-data">
			<div class="form-group">
				<label class="col-sm-3 control-label">上传账簿文件</label>

			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">文件：</label>
				<div class="col-sm-6">
					<input id="file" name="file" class="form-control" type="file"
						accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel">
				</div>
				<label class="col-sm-2 control-label">
					<a href="${ctx }/static/file/例子.xlsx" >点击下载例子</a>
				</label> 
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">&nbsp;</label>
				<div class="col-sm-8">
					<a class="btn btn-primary btn-del" onclick="submitHandler()">
						<i class="fa fa-play"></i>
						提交审核
					</a>
				</div>
			</div>
		</form>
	</div>
	<script type="text/javascript">
		var prefix = "${ctx}/system/ledger"
		$("#form-ledger-add").validate({
			rules : {
				file : {
					required : true,
				},
			}
		});
	
		function submitHandler() {
			if ($.validate.form()) {
	
				var formData = new FormData();
				formData.append("file", $("#file")[0].files[0]); //第一个file1代表后台文件属性名，第二个file1表示html中input的id
	
				formData.append("taxpayerId", "${taxpayerId}");
				$.ajax({
					type : "post",
					url : prefix + "/upload",
					data : formData,
					processData : false,
					contentType : false,
					dataType : 'json',
					success : function(data) {
						if (data.code == 0) {
							alert(data.msg);
							window.location.href = "${ctx}/system/ledger/trList";
						} else {
							alert("上传发出错误！");
						}
					},
					error : function(msg) {
						alert("无法解析文件！");
					}
				});
			}
		}
	</script>
</body>
</html>
